import javax.swing.text.*;
public class DigitDocumnet extends PlainDocument {  //负责创建文档类型的类 
   int count=1;
   public void insertString(int offset,String s,AttributeSet a) {
      char c=s.charAt(0);
      if(c<='9'&&c>='0'&&count<=8) {
          try{  super.insertString(offset,s,a);
                count++;
          }
          catch(BadLocationException e){}
      }
   }
   public void remove(int offset,int length) {
      try{  super.remove(offset,length);
            count--;
      }
      catch(BadLocationException e){}
   }
} 

